﻿@using Common.BaseLibrary.Authorization
@using DepartmentWork.Model

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@model List<DepartmentWork.Model.UserInfoViewModel>
<link href="~/Assets/plugins/bootstrap-treeview/css/bootstrap-treeview.css" rel="stylesheet" />
<script src="~/Assets/plugins/bootstrap-treeview/js/bootstrap-treeview.js"></script>


@{
    List<RoleViewModel> allRoleList = (List<RoleViewModel>)TempData["RoleList"];
}


<script>
    function DeleteUser(userId)
    {
        if (!confirm("请确认是否删除该人员？"))
        {
            return false;
        }
        window.location.href = '@Url.Action("DeleteUser", "Employee", new { area = "SystemSettingArea" })' + '?userId=' + userId;
    }

    function ShowParent(index) {
        if ($("#treeview li[data-nodeid='" + index + "']").css('display') == 'block')
        {
            $("#treeview li[data-nodeid='" + index + "']").hide(300);
            $("#span_" + index).attr('class', 'icon expand-icon glyphicon glyphicon-plus');
        }
        else
        {
            $("#treeview li[data-nodeid='" + index + "']").show(300);
            $("#span_" + index).attr('class', 'icon expand-icon glyphicon glyphicon-minus');
        }
        
    }
</script>

<div class="page-header">
    <div class="pull-left">
        <ol class="breadcrumb visible-sm visible-md visible-lg">
            <li><a href="@Url.Action("Index","Home",new{area=""})"><i class="icon fa fa-home"></i>主页</a></li>
            <li><a href="#"><i class="fa fa-envelope"></i>系统设置</a></li>
            <li class="active"><a href="#"><i class="fa fa-envelope"></i>人员管理</a></li>

        </ol>
    </div>
</div>

<div class="col-lg-12">
    <div class="col-sm-12">
        <label for="treeview"></label>
        <div id="treeview" class="treeview">
            <ul id="ul_user" class="list-group">
                @*                
                <li class="list-group-item node-treeview" data-nodeid="0">
                    <!-- 节点合并样式为 glyphicon-plus 展开样式为： glyphicon-minus-->
                    <span class="icon expand-icon glyphicon glyphicon-plus"></span>
                    <span class="icon node-icon"></span>
                    软件科 一级节点 节点 合并
                    <span class="badge">3 child elements</span>
                </li>*@

                <!-- class中 加 ‘node-selected’ 代表 选中 ，选中后改变样式 style="color:#FFFFFF;background-color:#428bca;"-->
                <li class="list-group-item node-treeview" >
                    <span id="span_1" onclick="ShowParent(1)" class="icon expand-icon glyphicon glyphicon-minus"></span>
                    <span class="icon node-icon"></span>
                    @CurrentUser.Department 
                    <span class="badge">共 @ViewBag.EmployeeCount 人</span>
                    @{
                        if (ViewBag.IsAdmin == true)
                        {
                             <span class="badge"><a style="color: white" data-toggle="modal" data-target="#myModal">
                      添加人员</a></span>
                        }
                    }
                </li>
                @{
                    for (int i = 0; i < this.Model.Count; i++)
                    {
                        var item = this.Model[i];
                        <li class="list-group-item node-treeview" data-nodeid="1">
                            <span class="indent"></span>
                            <span class="icon"></span>
                            <span class="icon node-icon"></span>
                            @item.DisplayName 
                            <span class="badge">
                                <a onclick="ShowEmployeeInfoModal('@item.UserId')" data-toggle="modal" data-target="#EmployeeInfoModal">详情</a>
                            </span>
                            @{
                                if (ViewBag.IsAdmin == true)
                                {
                                    <span class="badge">
                                        <a onclick="ShowEmployeeEditModal('@item.UserId')" data-toggle="modal" data-target="#EmployeeEditModal">编辑</a>
                                    </span>
                                <span class="badge">
                                      <a onclick="DeleteUser('@item.UserId')">删除</a>
                                   </span>
                                }
                            }
                        </li>
                    }
                }
            </ul>
        </div>
    </div>
</div>



<!-- 人员详情 模态框（Modal） -->

<script>
    function ShowEmployeeInfoModal(empId)
    {
        //alert(data["Status"]);
        $.ajax({
            type: "POST",
            //url: "/KSManager/SystemSettingArea/Employee/GetEmployeeInfo",
            url:'@Url.Action("GetEmployeeInfo","Employee",new{area="SystemSettingArea"})',
            data: "empId=" + empId,
            error: function () { alert("服务器出错！"); },
            success: function (data)
            {
                // $("#TaskBookInfoModal").attr("aria-hidden", "true");
                $("#lb_EmployeeName").text(data["UserName"]);
                $("#lb_EmployeeDisplayName").text(data["DisplayName"]);
                if (data["Enable"] == 0)
                {
                    $("#lb_EmployeeStatue").text('禁用状态');
                }
                else if (data["Enable"] == 1)
                {
                    $("#lb_EmployeeStatue").text('启用状态');
                }
            }
        });
    }

</script>

<div class="modal fade" id="EmployeeInfoModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">人员详情
                </h4>
            </div>
            <div class="modal-body" style="font-size: small">
                <div class="row">
                    <label class="col-md-3 control-label" for="text-input">登录名：</label>
                    <div class="col-md-9">
                        <label id="lb_EmployeeName" class="col-md-3 control-label" for="text-input"></label>
                    </div>
                </div>
                <hr />

                <div class="row">
                    <label class="col-md-3 control-label" for="text-input">展示名：</label>
                    <div class="col-md-9">
                        <label id="lb_EmployeeDisplayName" class="col-md-8 control-label" for="text-input"></label>
                    </div>
                </div>
                <hr />

                <div class="row">
                    <label class="col-md-3 control-label" for="text-input">状态：</label>
                    <div class="col-md-9">
                        <label id="lb_EmployeeStatue" class="col-md-8 control-label" for="text-input"></label>
                    </div>
                </div>
                
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">
                    关闭
                </button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal -->
</div>


<!-- 编辑人员 模态框（Modal） -->
    
<script>
    function ShowEmployeeEditModal(empId) {
        $("#hid_EditEmployeeId").val(empId);
        //alert(data["Status"]);
        $.ajax({
            type: "POST",
            url: "/DepartmetWork/SystemSettingArea/Employee/GetEmployeeInfo",
            data: "empId=" + empId,
            error: function () { alert("服务器出错！"); },
            success: function (data)
            {
                // $("#TaskBookInfoModal").attr("aria-hidden", "true");
                $("#lb_EmployeeEditName").text(data["UserName"]);
                $("#tb_EditEmployeeDisplayName").val(data["DisplayName"]);
                if (data["Enable"] == 0) {
                    $("#ck_EditEmployeeStatus").attr("checked", "");
                }
                else if (data["Enable"] == 1)
                {
                    $("#ck_EditEmployeeStatus").attr("checked", "true");
                }
                
                $("#EmployeeEditModal").find("input[type='radio']").each(function ()
                {
                    if ($(this).attr("id") == "ck_" + data["UserRole"])
                    {
                        $(this).attr("checked", "checked");
                    }
                });
            }
        });
    }

</script>

<div class="modal fade" id="EmployeeEditModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">编辑人员
                </h4>
            </div>
            <form action="@Url.Action("EditEmployee", "Employee")" method="POST" enctype="multipart/form-data">
                <input type="hidden" id="hid_EditEmployeeId" name="hid_EditEmployeeId" />
                <div class="modal-body">
                    <div class="row">
                        <label class="col-md-3 control-label" for="text-input">登录名：</label>
                        <div class="col-md-9">
                            <label id="lb_EmployeeEditName" class="col-md-3 control-label" for="text-input"></label>
                        </div>
                    </div>
                    <br />

                    <div class="row">
                        <label class="col-md-3 control-label" for="text-input">展示名：</label>
                        <div class="col-md-9">
                            <input id="tb_EditEmployeeDisplayName" name="tb_EditEmployeeDisplayName" style="border-color: cornflowerblue" class="form-control" placeholder="Text" type="text">                       
                        </div>
                    </div>
                    <br />

                    <div class="row">
                        <label class="col-md-3 control-label" for="text-input">状态：</label>
                        <div class="col-md-9">
                            <div class="checkbox-custom checkbox-inline" style="width: 50%">
                                <input id="ck_EditEmployeeStatus" name="ck_EditEmployeeStatus"  type="checkbox">
                                <label for="lb_EditEmployeeStatus">启用</label>
                            </div>
                        </div>
                    </div>
                    <br />
                    
                    <div class="row">
                        <label class="col-md-3 control-label" for="text-input">权限：</label>
                        <div class="col-md-9">
                            @{
                                if (allRoleList != null)
                                {
                                    for (int i = 0; i < allRoleList.Count(); i++)
                                    {
                                        <input  id="ck_@allRoleList[i].ROLE_ID" name="ck_EditRoleId" value="@allRoleList[i].ROLE_ID"  type="radio" />
                                        <label for="lb_EditRoleId">@allRoleList[i].ROLE_NAME</label>
                                        @:&nbsp;&nbsp;
                                        if (i % 2 != 0)
                                        {
                                            <br/>
                                        }
                                    }
                                }
                            }

                        </div>
                    </div>
                    <br />

                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">
                        关闭
                    </button>
                    <input type="submit" class="btn btn-primary"  value="保存并更新"/>
                </div>
            </form>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal -->
</div>


<!-- 模态框（Modal） -->

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <script src="~/Assets/plugins/chosen/chosen.jquery.min.js"></script>
    <script src="~/Assets/js/pages/form-elements.js"></script>

    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">新增人员
                </h4>
            </div>
            <div class="modal-body">
                <div class="alert alert-danger" id="div_CheckCreateRoleMessage" style="display:none">
                        <button type="button" class="close" data-dismiss="alert">×</button>
                        <strong><label id="lb_CheckCreateRoleMessage"></label></strong>
                    </div>
                <div class="row">
                    <label class="col-md-3 control-label">请输入员工号：</label>
                    <div class="col-md-9">
                        <input name="tb_UserRegisterName" id="tb_UserRegisterName"  class="form-control bk-noradius" type="text">
                    </div>
                </div>
                <br />
                
                 <div class="row">
                    <label class="col-md-3 control-label">默认密码：</label>
                    <div class="col-md-9">
                        <input value="Bjhg8888" disabled="disabled"  class="form-control bk-noradius" type="text">
                    </div>
                </div>
                <br />
                
                
                <div class="row">
                    <label class="col-md-3 control-label">绑定域账号：<br/>（域：BJ\）</label>
                    <div class="col-md-9">
                        <input name="tb_UserDomainName" id="tb_UserDomainName"  class="form-control bk-noradius" placeholder="BJ\" type="text">
                    </div>
                </div>
                <br />
                
                <div class="row">
                    <label class="col-md-3 control-label">请输入展示名：</label>
                    <div class="col-md-9">
                        <input name="tb_UserDisplayName" id="tb_UserDisplayName"  class="form-control bk-noradius" type="text">
                    </div>
                </div>
                <br />

                @{
                    List<TeamSpaceViewModel> listOfTeamspace = ViewBag.TeamspaceList;
                }
                <div class="row">
                    <label class="col-md-3 control-label">请选择要绑定的团队空间：</label>
                    <div class="col-md-9">

                        <select id="teamSpace_Select" class="form-control select2">
                            @for (int i = 0; i < listOfTeamspace.Count; i++)
                            {
                                var item = listOfTeamspace[i];
                                <option value="@item.TEAMSPACE_ID">@item.TEAMSPACE_NAME</option>
                            }
                        </select>
                    </div>
                </div>
                <br />
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">
                    关闭
                </button>
                <button type="button" class="btn btn-primary" onclick="ActiveUser()">
                    绑定
                </button>

            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal -->
</div>
<script>
    function ActiveUser()
    {
        var teamspaceId = $('#teamSpace_Select').val();
        var userId = $("#tb_UserRegisterName").val();
        var userDisplay = $("#tb_UserDisplayName").val();
        var userDomain = $("#tb_UserDomainName").val();

        if (userId == "") {
            $("#lb_CheckCreateRoleMessage").html("·用户名不能为空");
            $("#div_CheckCreateRoleMessage").css("display", "block");
            
            return false;
        }

        //window.location.href = 'Home/ActiveUser?teamspaceId=' + teamspaceId;
        window.location.href = '@Url.Action("ActiveUser","Employee")' +
            '?teamspaceId=' + teamspaceId + '&userId=' + userId + "&userDomainName=" + userDomain
            + "&userDisplay=" + userDisplay;
    }
</script>
